part of respond;

extension CROS on HttpRequest {
  bool get isPreflight => headers["access-control-request-method"] != null;
  void cros() {
    response.headers.add("Access-Control-Allow-Origin", "*");
    response.headers.add("Access-Control-Max-Age", 1728000);
    response.headers.add("Access-Control-Allow-Credentials", true);
    response.headers
        .add("Access-Control-Allow-Headers", "ticket, content-type");
    response.headers.add("Access-Control-Allow-Methods", "POST");
    // 这个如果不加，浏览器可能会用默认的方式解码，会导致错误
    response.headers.add("content-type", "application/json; charset=utf-8");
  }
}
